﻿using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;

namespace 用EFCore时如何实现一个分布式事务
{
    // 订单实体（属于OrderDb）
    public class Order
    {
        public int Id { get; set; }
        public int ProductId { get; set; }
        public int Quantity { get; set; }
        public DateTime CreateTime { get; set; }
    }

    // 库存实体（属于InventoryDb）
    public class Inventory
    {
        public int Id { get; set; }
        public int ProductId { get; set; }
        public int Stock { get; set; }
    }

    // 订单数据库上下文
    public class OrderDbContext : DbContext
    {
        public DbSet<Order> Orders { get; set; }

        public OrderDbContext(DbContextOptions<OrderDbContext> options) : base(options) { }
    }

    // 库存数据库上下文
    public class InventoryDbContext : DbContext
    {
        public DbSet<Inventory> Inventories { get; set; }

        public InventoryDbContext(DbContextOptions<InventoryDbContext> options) : base(options) { }
    }
}
